﻿<div class="editor-label">
    @Helpers.TryRenderRequiredTag(ViewData.ModelMetadata.IsRequired)
    @if (ViewData["FieldTitle"] != null)
    {
        @Html.Label(ViewData["FieldTitle"].ToString())
    }
    else
    {    
        @Html.LabelFor(model => model)

    }
</div>
<div class="editor-field">
    @if (ViewData.ModelMetadata.ModelType == typeof(DateTime) || ViewData["ForceDate"]!=null)
    {
        var g = "D" + Guid.NewGuid().ToString("N");
        var tempdate = DateTime.MinValue;
        if(ViewData.ModelMetadata.ModelType == typeof(DateTime))
        {
            tempdate=(DateTime)Model.Date;
        }else if(null!=Model)
        {
            DateTime.TryParse(Model.ToString(),out tempdate);
        }


            
        <span class="small-input">
            @if (tempdate == DateTime.MinValue)
            {
                @Html.TextBox("",
            string.Empty,
            new { id = g })
            }
            else
            {
                @Html.TextBox("",
                 string.Format("{0:yyyy-MM-dd}", tempdate),
            new { id = g })
            }
            <script type="text/javascript">                $(function () { $('#@(g)').datepicker(); });</script>
        </span>
    }
    else
    {
        @Html.TextBoxFor(model => model)
    }
    @Html.ValidationMessageFor(model => model)
</div>
